package puzzle;
import java.awt.Color;

public class DrawElement {
	
	private final static int BGHEIGTH = 400;
	private final static int BGWIDTH = 480;

	/**
	 * Static Function that displays the current state of the tray
	 * @param tray tray to display
	 */
	
	public static void init(Tray tray){
		StdDraw.setCanvasSize(BGHEIGTH, BGWIDTH);
		int width = (tray.getT_width());
		int heigth = (tray.getT_heigth());
		
		
		StdDraw.setXscale(0, width);
		StdDraw.setYscale(heigth, 0);
	}
	
	public static void Draw(Tray tray) {
		StdDraw.show(0);
		StdDraw.clear();
		int i=0;
		for(Block currentBlock : tray.getBlock()) {
			changecolor(currentBlock);
			StdDraw.filledRectangle(
					((float)currentBlock.getPosy()+(float)currentBlock.getWidth()/2),
					((float)currentBlock.getPosx()+(float)currentBlock.getHeight()/2), 
		    		(float)currentBlock.getWidth()/2,
		    		(float)currentBlock.getHeight()/2);
			StdDraw.setPenColor(Color.BLACK);
			StdDraw.rectangle(
					((float)currentBlock.getPosy()+(float)currentBlock.getWidth()/2),
					((float)currentBlock.getPosx()+(float)currentBlock.getHeight()/2), 
		    		(float)currentBlock.getWidth()/2,
		    		(float)currentBlock.getHeight()/2);
			i++;
		}
		StdDraw.show(10);
	}
	
	public static void changecolor(Block b){
		if(b.getHeight()==1&&b.getWidth()==1)
			StdDraw.setPenColor(Color.YELLOW);
		if(b.getHeight()==1&&b.getWidth()==2)
			StdDraw.setPenColor(Color.GREEN);
		if(b.getHeight()==2&&b.getWidth()==1)
			StdDraw.setPenColor(Color.BLUE);
		if(b.getHeight()==2&&b.getWidth()==2)
			StdDraw.setPenColor(Color.RED);
		
	}
}
